//
//  ViewController.m
//  ScrollView的优化和封装
//
//  Created by lorin on 16/3/16.
//  Copyright © 2016年 lorin. All rights reserved.
//

#import "ViewController.h"
#import "WHScrollAndPageView.h"
#import "FirstViewController.h"
#define NUM 4
@interface ViewController ()<WHcrollViewViewDelegate>
{
    WHScrollAndPageView *_whView;

}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //创建view（view中包含UIScrollView.UIPageControl,设置frame）
    _whView=[[WHScrollAndPageView alloc]initWithFrame:CGRectMake(0, 20, self.view.bounds.size.width, 200)];
    //将图片放倒imageView上
    NSMutableArray *tempArray=[NSMutableArray array];
    for (int i=1; i<=NUM; i++) {
        UIImageView *imageView=[[UIImageView alloc]init];
        imageView.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d.png",i]];
        [tempArray addObject:imageView];
    }
    //把imageView数组存到whView里
    [_whView setImageViewAry:tempArray];
    //把图片展示的view加到当前页面
    [self.view addSubview:_whView];
    //开启自动翻页
    [_whView shouldAutoShow:YES];
    //遵守协议
    _whView.delegate=self;
}
#pragma mark 协议里面方法,点击某一页
-(void)didClickPage:(WHScrollAndPageView *)view atIndex:(NSInteger)index{
    
    NSLog(@"第%li页面",index);
    
}
#pragma mark 界面消失的时候,停止自动滚动
-(void)viewDidAppear:(BOOL)animated{
    [_whView shouldAutoShow:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
